using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ItemFlyInAndOutAnimations
	{
		private Popup _popup;
		private Canvas _popupCanvas;
		private FrameworkElement _targetElement;
		private Point _targetElementPosition;
		private Image _targetElementClone;
		private static TimeSpan _flyInSpeed = TimeSpan.FromMilliseconds(300.0);
		private static TimeSpan _flyInSpeed2 = TimeSpan.FromMilliseconds(400.0);
		private static TimeSpan _flyOutSpeed = TimeSpan.FromMilliseconds(450.0);
		private static TimeSpan _flyOut2Speed = TimeSpan.FromMilliseconds(360.0);
		private static List<ItemFlyInAndOutAnimations> mListIncetancesToFlyIn = new List<ItemFlyInAndOutAnimations>();
		public ItemFlyInAndOutAnimations()
		{
			this._popup = new Popup();
			this._popupCanvas = new Canvas();
			this._popup.set_Child(this._popupCanvas);
		}
		public static void TitleFlyIn(FrameworkElement title)
		{
		}
		public static void TitleFlyOut(FrameworkElement title)
		{
			TranslateTransform translateTransform = new TranslateTransform();
			translateTransform.set_X(0.0);
			translateTransform.set_Y(0.0);
			title.set_RenderTransform(translateTransform);
			Rect rect = default(Rect);
			try
			{
				rect = ToolFunction.GetElementPos(title);
			}
			catch
			{
				return;
			}
			Image image = new Image();
			image.set_Source(new WriteableBitmap(title, null));
			Image image2 = image;
			Canvas canvas = new Canvas();
			canvas.get_Children().Add(image2);
			Canvas.SetTop(image2, rect.get_Y());
			Canvas.SetLeft(image2, rect.get_X());
			Popup popup = new Popup();
			popup.set_Child(canvas);
			Storyboard storyboard = new Storyboard();
			double arg_FB_0 = rect.get_X();
			double arg_FB_1 = rect.get_X() - 120.0;
			SineEase sineEase = new SineEase();
			sineEase.set_EasingMode(0);
			DoubleAnimation doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(arg_FB_0, arg_FB_1, sineEase, image2, Canvas.LeftProperty, ItemFlyInAndOutAnimations._flyOut2Speed);
			double arg_136_0 = rect.get_Y();
			double arg_136_1 = rect.get_Y() + 800.0;
			SineEase sineEase2 = new SineEase();
			sineEase2.set_EasingMode(1);
			doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(arg_136_0, arg_136_1, sineEase2, image2, Canvas.TopProperty, ItemFlyInAndOutAnimations._flyOut2Speed);
			storyboard.get_Children().Add(doubleAnimation);
			double arg_179_0 = 1.0;
			double arg_179_1 = 0.0;
			SineEase sineEase3 = new SineEase();
			sineEase3.set_EasingMode(0);
			doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(arg_179_0, arg_179_1, sineEase3, image2, UIElement.OpacityProperty, ItemFlyInAndOutAnimations._flyOut2Speed);
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(delegate(object sender, EventArgs e)
			{
				title.get_Dispatcher().BeginInvoke(delegate
				{
					popup.set_IsOpen(false);
					title.set_Opacity(1.0);
				});
			});
			title.set_Opacity(0.0);
			popup.set_IsOpen(true);
			storyboard.Begin();
		}
		public void ItemFlyIn()
		{
			if (this._popupCanvas.get_Children().get_Count() != 1)
			{
				return;
			}
			TranslateTransform translateTransform = new TranslateTransform();
			translateTransform.set_X(0.0);
			translateTransform.set_Y(0.0);
			this._targetElement.set_RenderTransform(translateTransform);
			this._targetElement.set_Opacity(1.0);
			this._popupCanvas.get_Children().Clear();
			Storyboard storyboard = new Storyboard();
			DoubleAnimation doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(-200.0, 0.0, new SineEase(), translateTransform, TranslateTransform.XProperty, ItemFlyInAndOutAnimations._flyInSpeed2);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(-150.0, 0.0, new SineEase(), this._targetElement, TranslateTransform.YProperty, ItemFlyInAndOutAnimations._flyInSpeed2);
			storyboard.get_Children().Add(doubleAnimation);
			double arg_10B_0 = 0.3;
			double arg_10B_1 = 1.0;
			SineEase sineEase = new SineEase();
			sineEase.set_EasingMode(1);
			doubleAnimation = ItemFlyInAndOutAnimations.CreateDoubleAnimation(arg_10B_0, arg_10B_1, sineEase, this._targetElement, UIElement.OpacityProperty, ItemFlyInAndOutAnimations._flyInSpeed2);
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(delegate(object sender, EventArgs e)
			{
				this._popup.set_IsOpen(false);
				this._popupCanvas.get_Children().Clear();
			});
			storyboard.Begin();
		}
		public static void FlyItemsIn()
		{
			using (List<ItemFlyInAndOutAnimations>.Enumerator enumerator = ItemFlyInAndOutAnimations.mListIncetancesToFlyIn.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ItemFlyInAndOutAnimations current = enumerator.get_Current();
					current.ItemFlyIn();
				}
			}
			ItemFlyInAndOutAnimations.mListIncetancesToFlyIn.Clear();
		}
		public void ItemFlyOut(FrameworkElement element, Action action)
		{
		}
		private static DoubleAnimation CreateDoubleAnimation(double from, double double_0, IEasingFunction easing, DependencyObject target, object propertyPath, TimeSpan duration)
		{
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_From(new double?(from));
			doubleAnimation.set_EasingFunction(easing);
			doubleAnimation.set_Duration(duration);
			Storyboard.SetTarget(doubleAnimation, target);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(propertyPath));
			return doubleAnimation;
		}
	}
}
